import Log4R from "shared/component/log/Log4R";
import { SkillServiceImpl } from "shared/modules/act/service/SkillServiceImpl";

import { AirState, CharacterState } from "shared/enums/CharacterState";



import { aninmClient, characterStateClient, effectClient, move2DClient, SkillClient } from "./clientLib";
// let i = 1;
const loginfo = Log4R.getLog('info');

SkillClient.setController(move2DClient)
SkillClient.onSkill(skillInputEntity => {
    // loginfo?.info('onSkill', skillInputEntity)
    if (!skillInputEntity.characterEntity) {
        print("skillInputEntity", skillInputEntity)
        throw ('no skillInputEntity.characterEntity')
    }
    effectClient.destory(skillInputEntity.characterEntity);//删除之前的特效
    if (skillInputEntity.stoped) {
        move2DClient.setCtrlEnable(skillInputEntity.character, true)
        move2DClient.setJumpEnable(skillInputEntity.character, true)
        move2DClient.setDodgeEnable(skillInputEntity.character, true)
        characterStateClient.ForceChangeCurrentStae({//技能结束时修改状态
            // anim: skillInputEntity.anim,
            state: CharacterState.none,
            humanModel: skillInputEntity.character
        })
        characterStateClient.autoState(skillInputEntity.character)
    } else if (skillInputEntity.skillConfig?.characterState) {
        if (!skillInputEntity.skillConfig.ctrl) {//设置技能期间是否可以控制摇杆移动
            move2DClient.setCtrlEnable(skillInputEntity.character, false)
            move2DClient.setJumpEnable(skillInputEntity.character, false)
            move2DClient.setDodgeEnable(skillInputEntity.character, true)
        } else {
            move2DClient.setCtrlEnable(skillInputEntity.character, true)
            move2DClient.setJumpEnable(skillInputEntity.character, true)
            move2DClient.setDodgeEnable(skillInputEntity.character, true)
        }
        const characterState = {
            // i: i++,
            ...skillInputEntity.skillConfig.characterState
        }
        // 计算状态
        characterStateClient.computeState({
            anim: skillInputEntity.anim,
            state: CharacterState.Skilling,
            stateInfo: characterState,
            humanModel: skillInputEntity.character
        })
    }
})
/** 技能暂停事件 */
SkillClient.onPause((characterEntity, pauseEntity) => {
    aninmClient.pause(characterEntity, pauseEntity)
    move2DClient.pause(characterEntity, pauseEntity)
    effectClient.pause(characterEntity, pauseEntity)
})
/** 特效事件 */
SkillClient.onEffect((charcterEntity, state) => {
    // loginfo?.info("onEffect", state)
    if (state.animEffect)
        effectClient.playEffect(charcterEntity, state.animEffect)
    if (state.hitEffect)
        effectClient.hitEffect(state.hitEffect)
})
SkillClient.onSkillStep((characterEntity, skillEntity) => {
    // loginfo?.info('skill pause', pauseEntity)
    // aninmClient.pause(characterEntity, pauseEntity)
    aninmClient.step(characterEntity, (skillEntity.currentFrame || 0) / 30)
})
SkillClient.onAnim((characterEntity, skillState) => {
    // loginfo?.info('skill pause', pauseEntity)
    // aninmClient.pause(characterEntity, pauseEntity)
    aninmClient.setSkillState(characterEntity, skillState)
})
